package t20211225;

import java.util.LinkedList;

/**
 * @Author: DengJia
 * @Date: 2021/12/25 15:23
 * @Description:
 */

public class Stack<T> {
    private LinkedList<T> storage = new LinkedList<>();

    public void push(T t) {
        storage.addFirst(t);
    }

    public T pop() {
        return storage.removeFirst();
    }

    public T peek() {
        return storage.getFirst();
    }

    public boolean empty() {
        return storage.isEmpty();
    }

    public String toString() {
        return storage.toString();
    }

    public static void main(String[] args) {
        Stack<String> stack = new Stack<>();
        java.util.Stack<String> stack1 = new java.util.Stack<>();
        for (String s : "my dog has fleas".split(" ")) {
            stack.push(s);
        }
        for (String s : "my dog has fleas".split(" ")) {
            stack1.push(s);
        }

        System.out.println("stack = " + stack);
        while (!stack.empty()) {
            System.out.print(stack.pop() + " ");
        }

        System.out.println();

        System.out.println("stack1 = " + stack1);
        while (!stack1.empty()) {
            System.out.print(stack1.pop() + " ");
        }
    }
}
